//import java.awt.EventQueue;

import javax.swing.JDialog;
import javax.swing.JFormattedTextField;
import javax.swing.JLabel;
import javax.swing.SwingConstants;
import javax.swing.JComboBox;
import javax.swing.JButton;





//import java.awt.ComponentOrientation;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.text.NumberFormat;

import javax.swing.JTextField;


@SuppressWarnings("serial")
public class Nowa_Gra extends JDialog {
    private JTextField textField;
    private JTextField textField_1;
    Controller kontroler;
    int intGracze,intBoty,iloscKasy,minZaklad;
    
    @SuppressWarnings("rawtypes")
    JComboBox comboBox;
    @SuppressWarnings("rawtypes")
    JComboBox comboBox_1;
    
    String[] iloscGraczy = {"2","3","4"};
    String[] iloscBotow = {"0","1","2","3"};
    
    private NumberFormat amountFormat = NumberFormat.getNumberInstance();

    /**
     * Create the dialog.
     */
    @SuppressWarnings({ "unchecked", "rawtypes" })
    public Nowa_Gra(final Controller kontroler,final Start start) {
        this.kontroler = kontroler;
        setTitle("Nowa Gra");
        setResizable(false);
        setModal(true);
        setAlwaysOnTop(true);
        setBounds(100, 100, 230, 225);
        getContentPane().setLayout(null);
        
        JLabel lblIloscGraczy = new JLabel("Ilosc graczy");
        lblIloscGraczy.setHorizontalAlignment(SwingConstants.CENTER);
        lblIloscGraczy.setBounds(10, 11, 102, 25);
        getContentPane().add(lblIloscGraczy);
        
        JLabel lblIloscBotow = new JLabel("Ilosc botow");
        lblIloscBotow.setHorizontalAlignment(SwingConstants.CENTER);
        lblIloscBotow.setBounds(112, 11, 102, 25);
        getContentPane().add(lblIloscBotow);
        
        comboBox = new JComboBox(iloscGraczy);
        comboBox.setBounds(10, 47, 88, 20);
        getContentPane().add(comboBox);
        
        comboBox_1 = new JComboBox(iloscBotow);
        comboBox_1.setBounds(122, 47, 92, 20);
        getContentPane().add(comboBox_1);
        
        JButton btnStworzGre = new JButton("Stworz Gre");
        btnStworzGre.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                if (Integer.parseInt(comboBox.getSelectedItem().toString())>Integer.parseInt(comboBox_1.getSelectedItem().toString())){
                    if (Integer.parseInt(textField.getText())!=0){
                        if (Integer.parseInt(textField.getText())>Integer.parseInt(textField_1.getText())){
                            if (Integer.parseInt(textField_1.getText())!=0){
                                intGracze = Integer.parseInt(comboBox.getSelectedItem().toString());
                                intBoty = Integer.parseInt(comboBox_1.getSelectedItem().toString());
                                iloscKasy = Integer.parseInt(textField.getText());
                                minZaklad = Integer.parseInt(textField_1.getText());
                                
                                kontroler.createGame(intGracze,intBoty,iloscKasy,minZaklad);

                                setVisible(false);
                                kontroler.startGame();
                            }
                        }
                    } 
                }
            }
        });
        btnStworzGre.setBounds(10, 154, 204, 31);
        getContentPane().add(btnStworzGre);
        
        textField = new JFormattedTextField(amountFormat);
        textField.setHorizontalAlignment(SwingConstants.RIGHT);
        textField.setText("0");
        textField.setBounds(10, 110, 88, 20);
        getContentPane().add(textField);
        textField.setColumns(10);
        
        textField_1 = new JFormattedTextField(amountFormat);
        textField_1.setText("0");
        textField_1.setHorizontalAlignment(SwingConstants.RIGHT);
        textField_1.setColumns(10);
        textField_1.setBounds(126, 110, 88, 20);
        getContentPane().add(textField_1);
        
        JLabel lblNewLabel = new JLabel("Ilosc zetonow");
        lblNewLabel.setHorizontalAlignment(SwingConstants.CENTER);
        lblNewLabel.setBounds(10, 85, 88, 14);
        getContentPane().add(lblNewLabel);
        
        JLabel lblMinZaklad = new JLabel("Min. zaklad");
        lblMinZaklad.setHorizontalAlignment(SwingConstants.CENTER);
        lblMinZaklad.setBounds(126, 85, 88, 14);
        getContentPane().add(lblMinZaklad);

    }
}
